
const app = getApp();

Page({
    data: {
        ifFAV: !0,
        fav: [],
        layer: !0,
        isCreate: !1,
        text: "",
        thumb_url: "",
        source_url: "",
        loading: !0,
        saving: !0,
        deny: !0,
        slideUp: !0,
        ecHotLine: {
            lazyLoad: !0
        },
        bmData: {
            date: ["07-22", "07-22", "07-22", "07-22"],
            zwk_number: [12336, 23412, 12342, 17234],
            zwk_hege: [12436, 23212, 15342, 17834]
        },
        sjJzData: {
            date: ["07-22", "07-22", "07-22"],
            avgfs: [12336, 12342, 17234],
            minfs: [12436, 23212, 17834]
        },
        closeHint: !0
    },


    onLoad: function (i) {
        var that = this;
        console.log(i)
        var zdy = i.zdy
        wx.request({
            url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=51488&callback=?",
            method: "GET",
            data: {
                zdy: zdy,
                limits: 100
            },
            success: function (o) {
                var jsonStr = o.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                };
                console.log(theJson.lists[0].gangwei)
                that.setData({
                    theList: theJson.lists[0],
                    success: !0
                })
                var gangwei = theJson.lists[0].gangwei
                var zhiweidaima = theJson.lists[0].zhiweidaima
                wx.request({
                    url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=51488&callback=?",
                    method: "GET",
                    data: {
                        gangwei: gangwei,
                        limits: 100
                    },
                    success: function (o) {
                        var jsonStr = o.data;
                        jsonStr = jsonStr.replace("(", "");
                        jsonStr = jsonStr.replace(")", "");
                        if (typeof jsonStr != 'object') {
                            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                            var theJson = JSON.parse(jsonStr);
                        };
                        console.log(theJson.lists)
                        that.setData({
                            theListData: theJson.lists
                        })
                    }
                });
                
            }
        });

    },
    onUnload: function () {

    },
    onShow: function () {
        wx.getStorageSync("position");
        var t = this;
        wx.getSetting({
            success: function (e) {
                0 == e.authSetting["scope.writePhotosAlbum"] && t.setData({
                    deny: !1
                }), e.authSetting["scope.writePhotosAlbum"] && t.setData({
                    deny: !0
                });
            }
        });
    },
    slideShow: function (t) {
        this.setData({
            layer: !1
        });
    },
    closeLayer: function () {
        this.setData({
            layer: !0
        });
    },
    createImg: function () {
        if (this.setData({
                layer: !0,
                loading: !1
            }), i) {
            var t = this;
            wx.request({
                url: o.globalData.request_url + "api/zhiweiku/getBill.php",
                method: "POST",
                data: {
                    province: "国家公务员",
                    zhiwei: t.data.list.zwk_zw.value,
                    zhiweidaima: t.data.list.zwk_zhiweidaima.value,
                    bumen: t.data.list.zwk_yrsj.value,
                    bmdm: t.data.list.zwk_bmdm.value
                },
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                success: function (e) {
                    200 == e.data.code && t.setData({
                        thumb_url: e.data.list.thumb,
                        source_url: e.data.list.url
                    }), setTimeout(function () {
                        t.setData({
                            isCreate: !0,
                            loading: !0
                        });
                    }, 500);
                }
            }), i = !1;
        } else this.setData({
            isCreate: !0,
            loading: !0
        });
    },
    closeCreate: function () {
        this.setData({
            isCreate: !1
        });
    },
    saveImage: function () {
        this.setData({
            saving: !1
        });
        var t = this;
        wx.getSetting({
            success: function (e) {
                e.authSetting["scope.writePhotosAlbum"] ? t.downImgFile() : wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function () {
                        t.downImgFile();
                    },
                    fail: function () {
                        t.setData({
                            saving: !0,
                            deny: !1
                        }), wx.showToast({
                            icon: "none",
                            title: "保存失败！您已经拒绝授权访问相册"
                        });
                    }
                });
            }
        });
    },
    downImgFile: function () {
        var t = this.data.source_url,
            e = this;
        wx.downloadFile({
            url: t,
            success: function (t) {
                wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function (t) {
                        wx.showToast({
                            title: "保存图片成功！"
                        }), e.setData({
                            isCreate: !1,
                            saving: !0
                        });
                    },
                    fail: function (t) {
                        wx.showToast({
                            title: "保存图片失败！",
                            icon: "none"
                        });
                    }
                });
            },
            fail: function (t) {
                wx.showModal({
                    title: "提示",
                    content: "下载图片失败，请检查网络"
                });
            },
            complete: function () {
                e.setData({
                    loading: !0,
                    saving: !0
                });
            }
        });
    },
    onShareAppMessage: function (t) {
        return {
            title: "国考小助手",
            path: "/pages/index/index"
        };
    },
    openSetting: function () {
        wx.showModal({
            content: "检测到您还没打开保存照片到本地相册的权限，是否去设置打开",
            confirmColor: "#FFA500",
            success: function (t) {
                t.confirm ? wx.openSetting() : t.cancel;
            }
        });
    },

    unique: function (arr) {
        return Array.from(new set(arr))
    },
    unjoin: function (t) {
        db.collection('userInfo').get({ //寻找到对应集合，如果没有记录则添加记录
            success: res => {
                console.log(res.data[0].fav)



            }
        })
    },

    join: function (t) {
        var e = this,
            i = t.currentTarget.dataset.type;
        db.collection('userInfo').get({ //寻找到对应集合，如果没有记录则添加记录
            success: res => {
                // console.log(res.data[0].favc)
                e.data.fav.push(e.data.theList.zhiweidaima)
                var arr = e.data.fav.concat(res.data[0].nnum)
                var arr1 = res.data[0].favc.concat(e.data.theList);

                console.log(arr1)
                wx.setStorageSync('openid', res.data[0]._openid)

                db.collection('userInfo').where({
                    _openid: res.data[0]._openid,
                }).update({
                    data: {
                        favc: arr1,
                        fav: arr
                    },
                    success(res) {
                        e.setData({
                            ifFAV: !1
                        })
                        console.log(res)
                    },
                    fail(res) {
                        console.log(res)
                    }
                })

            }
        })
    },
    openClass: function (t) {
        var e = t.currentTarget.dataset.id,
            a = t.currentTarget.dataset.cid,
            i = t.currentTarget.dataset.gid;
        wx.navigateToMiniProgram({
            appId: e,
            path: "pages/course/course?courseid=" + a + "&goodsid=" + i,
            success: function (t) {
                console.log(t);
            }
        });
    },
    slideUp: function () {
        this.setData({
            slideUp: !0
        });
    },
    lookMore: function () {
        this.setData({
            slideUp: !1
        });
    },
    getSubcribeMsg: function (t) {
        var e = t.currentTarget.dataset.type,
            a = this,
            i = this.data.list,
            n = t.currentTarget.dataset.tiaoji,
            s = "B2Nk3iP5-mIAtq2irhGRTZoi1j1XBfc02G9KmFpMjHU";
        wx.requestSubscribeMessage({
            tmplIds: [s],
            success: function (t) {
                "requestSubscribeMessage:ok" == t.errMsg && ("accept" == t[s] && wx.request({
                    url: o.globalData.request_url + "api/zhiweiku/gk/zw_push.php",
                    method: "POST",
                    data: {
                        action: e,
                        zw_id: a.data.id,
                        is_tiaoji: n,
                        openid: wx.getStorageSync("openId")
                    },
                    header: {
                        "content-type": "application/x-www-form-urlencoded"
                    },
                    success: function (t) {
                        200 == t.data.code ? (wx.showToast({
                            title: t.data.msg,
                            icon: "none"
                        }), i.is_subscribe = "addQueue" == e ? 1 : 0, a.setData({
                            list: i,
                            closeHint: !0
                        })) : wx.showToast({
                            title: t.data.msg,
                            icon: "none"
                        });
                    }
                }), "reject" == t[s] && a.setData({
                    closeHint: !1
                }));
            },
            fail: function (t) {
                "requestSubscribeMessage:fail cancel" == t.errMsg && a.setData({
                    closeHint: !1
                });
            }
        });
    },
    closeHint: function () {
        this.setData({
            closeHint: !0
        });
    },
    gozx: function () {
        wx.navigateTo({
            url: '../../xiaoneng/xiaoneng',
        })
    },
    // getLesson: function () {
    //     var t = this,
    //         e = wx.getStorageSync("position").substring(0, 2),
    //         a = 0;
    //     "ios" == wx.getSystemInfoSync().platform && (a = 1), wx.request({
    //         url: "https://defen.huatu.com/api/snj/v1/open/online/CountryExamCourseList",
    //         method: "GET",
    //         data: {
    //             exam_type_id_set: 8,
    //             adapt_place: e,
    //             is_free: a
    //         },
    //         success: function (e) {
    //             200 == e.data.code && t.setData({
    //                 rec: e.data.data
    //             });
    //         }
    //     });
    // },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        var area = wx.getStorageSync('area')
        var agent = wx.getStorageSync('agent')
        var page = wx.getStorageSync('page')
        return {
            title: '2021国家公务员招录考试职位表',
            path: 'pages/search/search/search?area=' + area + '&agent=' + agent + '&page=' + page
        }
    },
    /**分享到朋友圈*/
    onShareTimeline: function () {
        var area = wx.getStorageSync('area')
        var agent = wx.getStorageSync('agent')
        var page = wx.getStorageSync('page')
        return {
            title: '2021国家公务员招录考试职位表',
            path: 'pages/search/search/search?area=' + area + '&agent=' + agent + '&page=' + page
        }
    }
});